import React, {useCallback, useContext} from "react";
import { RouterContext } from "./RouterContext";

export default function Link({ to, children }) {

      const context = useContext(RouterContext);

      const hrefLink = useCallback((e) => { 
            e.preventDefault(); 
            // 我们需要通过history改变地址栏内容
            context.history.push(to);
      }, []);

      return <a href={to} onClick={hrefLink}>{children}</a>;
}
